﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;

namespace AppConfigDataProxy
{
    /// <summary>
    /// Interface to access data about Application configs
    /// </summary>
    public interface IAppConfigDataProxy
    {
        /// <summary>
        /// Get config information for given application in xml
        /// </summary>
        /// <param name="appid">Application id</param>
        /// <returns>Config information for given application in xml</returns>
        AppInfo GetAppConfig(string appid );

        /// <summary>
        /// Get schema for current config version
        /// </summary>
        /// <returns>xsd schema</returns>
        XmlElement GetSchema();

        /// <summary>
        /// Get complete config information for all applications.
        /// </summary>
        /// <returns>Array of config app information</returns>
        AppInfo[] GetConfig( );

        /// <summary>
        /// Set Application Configuration for a specific Application
        /// </summary>
        /// <param name="appInfo">Containe appId and new app config for this app</param>
        /// <returns>Updated application config version</returns>
        int SetAppConfig(AppInfo appInfo);

        /// <summary>
        /// Set configuration information for all applications
        /// </summary>
        /// <param name="appConfigs">Array of config information for all applications</param>
        /// <param name="schema">xsd schema for config</param>
        /// <returns></returns>
        int SetConfig(AppInfo[] appConfigs, XmlElement schema);

        /// <summary>
        /// Creates a new application (if provided appid is not already used)
        /// and either sets it’s config to xml provided 
        /// </summary>
        /// <param name="appInfo">Containe appId and config information</param>
        /// <returns>Updated app config version</returns>
        int AddApp(AppInfo appInfo);
        
        /// <summary>
        /// Remove a specific application from config
        /// </summary>
        /// <param name="appid">Application id what need to be remove</param>
        void RemoveApp(string appid);

        /// <summary>
        /// Rolls back application configuration to the requested version 
        /// </summary>
        /// <param name="appid">Application Id what want to roll back</param>
        /// <param name="requestedAppConfigVersion">version to which want to roll back</param>
        /// <returns>updated application config version</returns>
        int RollBackApp(string appid, int requestedAppConfigVersion);
        
        /// <summary>
        /// Rolls back application configuration to the previous version
        /// </summary>
        /// <param name="appid">Application Id what want to roll back</param>        
        /// <returns>updated application config version</returns>
        int RollBackApp( string appid );

        /// <summary>
        /// Rolls back configuration to the requested version
        /// </summary>
        /// <param name="requestedConfigVersion">version to which want to roll back</param>
        /// <returns>Update config version</returns>
        int RollBack(int requestedConfigVersion);

        /// <summary>
        /// Rolls back configuration to the previous version
        /// </summary>        
        /// <returns>Update config version</returns>
        int RollBack( );

        /// <summary>
        /// Get current version of the requested application config
        /// </summary>
        /// <param name="appId">Application id</param>
        /// <returns>Current application config version</returns>
        int GetAppVersion(string appId);

        /// <summary>
        /// Get current config version
        /// </summary>
        /// <returns>Current config version</returns>
        int GetVersion();
        
        /// <summary>
        /// Get the list of all applications on current config version
        /// </summary>
        /// <returns>Array of application id</returns>
        string[] GetAppList();

        /// <summary>
        /// Delete all information about all Application and config
        /// from data without possibility to rollback
        /// </summary>
        void ClearAll();

    }
}
